package zhaolu.com.example.Delicacy.MySQL;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class MySQLHelper {
    private static final String CLS = "com.mysql.jdbc.Driver";
    private static final String URL = "jdbc:mysql://172.27.157.97:3306/sifang";
    private static final String USER = "root";
    private static final String PWD = "Ch786616973";

    public static Connection connection;
    public static Statement statement;
    public static CallableStatement callableStatement;
    public static ResultSet resultSet;

    public static void getConnection() {
        try {
            Class.forName(CLS);
            connection = DriverManager.getConnection(URL, USER, PWD);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static void closeAll() {
        try {
            if (resultSet != null) {
                resultSet.close();
                resultSet = null;
            }
            if (statement != null) {
                statement.close();
                statement = null;
            }
            if (callableStatement != null) {
                callableStatement.close();
                callableStatement = null;
            }
            if (connection != null) {
                connection.close();
                connection = null;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
